// Date.h
// Written by Jaeseok Kim (jseokkim@hotmail.com)
// 03/29/2010

#include <string>

using namespace std;

#ifndef DATE_H_
#define DATE_H_

// C++ lacks of Date class. This class supports minimum functionality necessary to find its previous date.
class Date
{
public:
    Date() : nYear(0), nMonth(0), nDay(0){}
    Date(const char *);
    // Copy constructor
    Date(const Date &InputDate){
        nYear = InputDate.getYear();
        nMonth = InputDate.getMonth();
        nDay = InputDate.getDay();
    }
    void prevDate();
    bool isLeapYear() const{return !isValidYear() ? false : 
        (nYear % 400 == 0) ? true :
        (nYear % 100 == 0) ? false :
        (nYear % 4 == 0) ? true : false;}
    bool isValidDate() const {return isValidYear() && isValidMonth() && isValidDay();}
    int getYear() const {return nYear;}
    int getMonth() const {return nMonth;}
    int getDay() const {return nDay;}
    string toString();
    
private:
    static const int anDayOfMonth[13];
    bool isValidNumber(char ch) const {return (ch >= '0') && (ch <= '9');}
    bool isValidYear() const {return (nYear >= 1) && (nYear <= 9999);}
    bool isValidMonth() const {return (nMonth >= 1) && (nMonth <= 12);}
    bool isValidDay() const {return (nDay >= 1) && (nDay <= ((isLeapYear() && nMonth == 2) ? 29 : anDayOfMonth[nMonth]));}

    int nYear;
    int nMonth;
    int nDay;
};

#endif /*DATE_H_*/
